package mka.puzzle.util;

import java.security.SecureRandom;
import java.util.Random;

import mka.puzzle.shape.Circle;
import mka.puzzle.shape.Eclipse;
import mka.puzzle.shape.Point;
import mka.puzzle.shape.Rectangle;
import mka.puzzle.shape.Shape;
import mka.puzzle.shape.ShapeList;
import mka.puzzle.shape.Square;
import mka.puzzle.shape.Triangle;

/***
 * Function
 * 
 * @version 20131124
 * 
 * @author NguyenBB
 */
public class Function {

	/**
	 * addRandomShape
	 * 
	 * Add Shape (0: Rectangle, 1: Square, 2: Circle)
	 * 
	 * @param list
	 */
	public static void addRandomShape(ShapeList list) {
		int choose = randNumber(5);
		if (choose == 0) {
			list.addShape(new Square(new Point(randNumber(1000),
					randNumber(500)), randNumber(100)));
		} else if (choose == 1) {
			list.addShape(new Circle(new Point(randNumber(1000),
					randNumber(500)), randNumber(100)));
		} else if (choose == 2) {
			list.addShape(new Rectangle(new Point(randNumber(1000),
					randNumber(500)), randNumber(100), randNumber(100)));
		} else if (choose == 3) {
			list.addShape(new Eclipse(new Point(randNumber(1000),
					randNumber(500)), randNumber(100), randNumber(100)));
		} else if (choose == 99) {
			list.addShape(new Triangle(new Point(randNumber(500),
					randNumber(500)), new Point(randNumber(500),
							randNumber(500)), new Point(randNumber(500),
									randNumber(500))));
		}
	}

	/**
	 * createRandomShapeList
	 * 
	 * Add Shape (0: Rectangle, 1: Square, 2: Circle)
	 * 
	 * @param list
	 * @return ShapeList
	 */
	public static ShapeList createRandomShapeList(int numberList) {
		// int choose = randNumber(3);
		ShapeList shapeList = new ShapeList();
		for (int i = 0; i < numberList; i++) {
			shapeList.addShape((Shape) createRandomShape());
		}
		return shapeList;
	}

	// public static ShapeList createRandomShapeList(int numberList) {
	// int choose = randNumber(3);
	// ShapeList list = new ShapeList();
	//
	// for (int i = 0; i < numberList; i++) {
	// if (choose == 0) {
	// list.addShape(new Square(new Point(randNumber(10),
	// randNumber(10)), randNumber(100)));
	// } else if (choose == 1) {
	// list.addShape(new Circle(new Point(randNumber(10),
	// randNumber(10)), randNumber(10)));
	// }
	// }
	//
	// return list;
	// }

	/**
	 * createRandomPoint
	 * 
	 * Create Point.
	 * 
	 * @return Point
	 */
	public static Point createRandomPoint(int number) {
		Point point = new Point(randNumber(number), randNumber(number));
		return point;
	}

	/**
	 * createRandomShape
	 * 
	 * Create Shape (0: Rectangle, 1: Square, 2: Circle)
	 * 
	 * @return
	 * 
	 * @return Shape
	 */
	static int randomNumber = 50;

	public static Object createRandomShape() {

		int choose = randNumber(2);
		if (choose == 0) {
			return new Square(createRandomPoint(randomNumber),
					randNumber(randomNumber));
		} else if (choose == 1) {
			return new Circle(createRandomPoint(randomNumber),
					randNumber(randomNumber));
		} else {
			return new Rectangle(createRandomPoint(randomNumber),
					randNumber(randomNumber), randNumber(randomNumber));
		}
	}

	/**
	 * randNumber
	 * 
	 * Generate random number base input number
	 * 
	 * @param number
	 *            int
	 * @return int
	 */
	public static int randNumber(int number) {
		return new SecureRandom().nextInt(number);
	}
}
